﻿/**
 * 
 * 解决UserControl调用Flyout无效果问题:
 * 
 * 1.Flyout必须放置在Control:MetroWindow中，所以UserControl不能直接调用
 *   需在主窗体中设置:
 *      <Control:MetroWindow.Flyouts>
 *          <Control:FlyoutsControl>
 *              <Control:Flyout></Control:Flyout>
 *          </Control:FlyoutsControl>
 *      </Control:MetroWindow.Flyouts>
 * 2:使用UserControl调用主窗体中的Flyout
 *   Window ParentWindow = Window.GetWindow(this);   UserControl -> Window  获得父层级窗体
 *   object obj = ParentWindow.FindName("AddTemplateFlyout");  通过父层级窗体获得父层级窗体下的Flyout控件
 *   Flyout flyout = obj as Flyout;  转型
 *   flyout.IsOpen = !flyout.IsOpen; 设置开启属性
 **/
namespace metro_wpf.Views
{
    using MahApps.Metro.Controls;
    using metro_wpf.Function;
    using metro_wpf.ViewModel;
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;

    /// <summary>
    /// SVNProjectView.xaml 的交互逻辑
    /// </summary>
    public partial class SVNProjectView : UserControl
    {
        public object ShowMessageAsync { get; private set; }

        public SVNProjectView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 加载模板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScrollView_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        public void AddTemplate_Click(object sender, RoutedEventArgs e)
        {
            //Tile tile = new Tile();
            //Random random = new Random();
            //tile.Title = "Game";
            //tile.Count = "Game";
            //tile.HorizontalTitleAlignment = HorizontalAlignment.Right;
            //tile.Style = (Style)FindResource("LargeTileStyle");
            //tile.Margin = new Thickness(3);
            //tile.Background = new SolidColorBrush(Colors.Teal);
            //wrapPanel.Children.Add(tile);

            Window ParentWindow = Window.GetWindow(this);
            object obj = ParentWindow.FindName("AddTemplateFlyout");
            Flyout flyout = obj as Flyout;
            flyout.IsOpen = !flyout.IsOpen;
        }
    }
}
